package com.itwill.ecom.board;

import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository("boardDao")
public class BoardDaoImpl implements BoardDao {
	public final static String namespace="com.itwill.ecom.board.BoardMapper";
	@Autowired
	private SqlSession session;

	public SqlSession getSession() {
		return session;
	}

	public void setSession(SqlSession session) {
		System.out.println("#### BoardDao() : setSession()");
		this.session = session;
	}
	
	public BoardDaoImpl() {
		System.out.println("#### BoardDao() : 디폴트생성자 호출  ");
	}

	@Override
	public int create(BoardBeans boardBeans){
		return session.insert(namespace + ".create", boardBeans);
	}

	@Override
	public List<BoardBeans> readAll(HashMap<String, String> pageMap){
		return session.selectList(namespace + ".readAll", pageMap);
	}

	@Override
	public List<BoardBeans> readByType(HashMap<String, String> pageMap){
		return session.selectList(namespace + ".readByType", pageMap);
	}

	@Override
	public BoardBeans readByNo(int boardno){
		return session.selectOne(namespace + ".readByNo", boardno);
	}
	
	@Override
	public List<BoardBeans> readByNickname(HashMap<String, String> pageMap){
		return session.selectList(namespace + ".readByNickname", pageMap);
	}
	
	@Override
	public List<BoardBeans> readById(HashMap<String, String> pageMap){
		return session.selectList(namespace + ".readById", pageMap);
	}

	@Override
	public List<BoardBeans> readByTitle(HashMap<String, String> pageMap){
		return session.selectList(namespace + ".readByTitle", pageMap);
	}

	@Override
	public List<BoardBeans> readByContent(HashMap<String, String> pageMap){
		return session.selectList(namespace + ".readByContent", pageMap);
	}
	
	@Override
	public int readAllCount(){
		return session.selectOne(namespace + ".readAllCount");
	}
	
	@Override
	public int readCountByType(String type){
		return session.selectOne(namespace + ".readCountByType", type);
	}

	@Override
	public int readMaxNo(String id){
		return session.selectOne(namespace + ".readMaxNo", id);
	}
	
	@Override
	public int update(BoardBeans updateBoard){
		return session.update(namespace + ".updateBoard", updateBoard);
	}

	@Override
	public int updateShow(int boardno){
		return session.update(namespace + ".updateShow", boardno);
	}

	@Override
	public int updateRecommend(int boardno){
		return session.update(namespace + ".updateRecommend", boardno);
	}
	
	@Override
	public int delete(int board_no){
		return session.delete(namespace + ".delete", board_no);
	}	
}